// pages/Conveinfo/index/index.js
var app = getApp();
var ikz = require('../../Common/tools.js');
var arrs = [];


Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner_info: '', //banner图信息
    conven_type_info: '', //所有分类信息
    all_browse: '', //总浏览量
    all_release: '', //总发布数
    conven_info: '', //当前显示信息
    page: 1, //页数
    limit: 6, //每页条数
    conven_top_info: '', //优选信息
    shop_info: '', //商家信息
    bg_today: '#0AC4BA', //今日信息背景色
    co_today: '', //今日信息字体色
    bg_yesterday: '', //昨日信息背景色
    co_yesterday: '', //昨日信息字体色
    prodis: 'none', //底部提示是否显示
    imgnum: 1, //banner第几张
    indicatorDots: true,
    scrollLeft: 20,
    tanchuangWrap: 'none' //弹窗显示隐藏
  },
  //banner变化
  swiperChange: function(e) {
    var imgnum = e.detail.current + 1;
    this.setData({
      imgnum: imgnum,
    });
  },
  //跳转到图片页
  toImg: function(e) {
    var id = e.currentTarget.dataset.id;
    var typ = 'ban';
    var com = 'home';
    var data = {
      id: id,
      typ: typ,
      com: com,
    }
    ikz.nav('../../Home/images/images', 'n', data);
  },
  //跳转便民发布
  toForm: function (e) {
    var tid = e.currentTarget.dataset.tid;
    var data = {
      tid: tid,
    }
    ikz.nav('../../Release/addinfo/addinfo', 'n', data);
   this.setData({
     tanchuangWrap:'none',
   })
  },
  // 便民信息弹窗消失
  tanchuangWrapclick: function() {
    var bg_today = 'linear-gradient(-135deg, #0AC4BA 0%, #2BDA8E 100%)';
    var co_today = '#fff';
    var bg_yesterday = '#fff';
    var co_yesterday = '#000';
    var tanchuangWrap = 'none';
    this.setData({
      bg_today: bg_today, //今日信息背景色
      co_today: co_today, //今日信息字体色
      bg_yesterday: bg_yesterday, //昨日信息背景色
      co_yesterday: co_yesterday, //昨日信息字体色
      tanchuangWrap: tanchuangWrap,
    })
  },
  // 点击弹窗内容防止关闭
  tanchuangWrapclick2:function(){
    var that = this;
    that.setData({
      tanchuangWrap:'block',
    })
  },
  //选择分类
  chooseType: function(e) {
    var that = this;
    var bg_today = '#fff';
    var co_today = '#000';
    var bg_yesterday = 'linear-gradient(-135deg, #0AC4BA 0%, #2BDA8E 100%)';
    var co_yesterday = '#fff';
    var tanchuangWrap = 'block';
    that.setData({
      bg_today: bg_today, //今日信息背景色
      co_today: co_today, //今日信息字体色
      bg_yesterday: bg_yesterday, //昨日信息背景色
      co_yesterday: co_yesterday, //昨日信息字体色
      tanchuangWrap: tanchuangWrap,
    })
  },
  //拨打电话
  toPhone: function(e) {
    var phone = this.data.shop_info.self_phone;
    wx.makePhoneCall({
      phoneNumber: phone,
    })

  },
  // 置顶
  toTop: function() {
    wx.pageScrollTo({
      scrollTop: 0
    })
  },

  //跳转到优选页
  toPrefe: function(e) {
    ikz.nav('../prefelist/prefelist', 'n')
  },

  //跳转到详情页
  toContent: function(e) {
    var cid = e.currentTarget.dataset.cid;
    var data = {
      cid: cid,
    }
    ikz.nav('../content/content', 'n', data);
  },

  //分类列表
  chooseSon: function(e) {
    var tid = e.currentTarget.dataset.tid;
    var data = {
      tid: tid,
    }
    ikz.nav('../typelist/typelist', 'n', data);
  },

  // //数字转换
  // changeNum(num) {
  //   if (num > 0 && num < 10000) {
  //     num = num / 100;
  //     num = Math.ceil(num) / 10;
  //     var newnum = num + 'k';
  //   } else if (num >= 10000) {
  //     num = num / 1000;
  //     num = Math.ceil(num) / 10;
  //     var newnum = num + 'w';
  //   } else {
  //     var newnum = 0;
  //   }
  //   return newnum;
  // },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    // 页面初始化 options为页面跳转所带来的参数

    ikz.over(this);
    var that = this;
    var page = 1;
    var limit = that.data.limit;
    var bg_today = 'linear-gradient(-135deg, #0AC4BA 0%, #2BDA8E 100%)';
    var co_today = '#fff';
    var bg_yesterday = '#fff';
    var co_yesterday = '#000';
    var data = {
      page: page,
      limit: limit,
    };
    var path = 'Conven/index';
    ikz.request(path, data, false, (res) => {
      if (res.data.conven_info.length) {
        for (var i = 0; i < res.data.conven_info.length; i++) {
          if (res.data.conven_info[i].conven_top == 2) {
            arrs.push(res.data.conven_info)
          }
        }
      }
      if (res.data.status == 'success') {
        var all_browse = res.data.shop_info.self_all_browse;
        var all_release = res.data.all_release;

        that.setData({
          banner_info: res.data.banner_info,
          conven_type_info: res.data.conven_type_info,
          all_browse: all_browse,
          all_release: all_release,
          conven_info: res.data.conven_info,
          shop_info: res.data.shop_info,
          conven_top_info: res.data.conven_top_info,
          page: page,
          bg_today: bg_today, //今日信息背景色
          co_today: co_today, //今日信息字体色
          bg_yesterday: bg_yesterday, //昨日信息背景色
          co_yesterday: co_yesterday, //昨日信息字体色
          prodis: 'none',
          tanchuangWrap: 'none' //便民信息弹窗
        });
        ikz.hide(that);
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var bg_today = 'linear-gradient(-135deg, #0AC4BA 0%, #2BDA8E 100%)';
    var co_today = '#fff';
    var bg_yesterday = '#fff';
    var co_yesterday = '#000';
    this.setData({
      bg_today: bg_today, //今日信息背景色
      co_today: co_today, //今日信息字体色
      bg_yesterday: bg_yesterday, //昨日信息背景色
      co_yesterday: co_yesterday, //昨日信息字体色
      tanchuangWrap: 'none' //便民信息弹窗
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  onReachBottom: function() {
    wx.showLoading({
      title: '玩命加载中',
    })
    var that = this;
    var page = that.data.page + 1;
    var old_info = that.data.conven_info;
    that.setData({
      page: page,
    })
    var limit = that.data.limit;
    var data = {
      page: page,
      limit: limit,
    }
    var path = 'Conven/indexfen';
    ikz.request(path, data, false, (res) => {
      console.log(res);
      if (res.data.status == 'success') {
        var new_info = res.data.conven_info;
        if (new_info.length) {
          if (new_info.length) {
            for (var i = 0; i < new_info.length; i++) {
              if (new_info[i].conven_top == 2) {
                arrs.push(new_info)
              }
            }
          }
          var all_info = old_info.concat(new_info);
          var prodis = 'none';
        } else {
          var all_info = old_info;
          var prodis = 'block';
        }
        that.setData({
          conven_info: all_info,
          prodis: prodis,
        })
        // 隐藏导航栏加载框  
        wx.hideNavigationBarLoading();
        // 停止下拉动作  
        wx.stopPullDownRefresh();
        wx.hideLoading()
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showLoading({
      title: '刷新中..',
    })
    var that = this;
    var page = 1;
    var limit = that.data.limit;
    var data = {
      page: page,
      limit: limit,
    };
    var path = 'Conven/index';
    ikz.request(path, data, false, (res) => {
      if (res.data.conven_info.length) {
        for (var i = 0; i < res.data.conven_info.length; i++) {
          if (res.data.conven_info[i].conven_top == 2) {
            arrs.push(res.data.conven_info)
          }
        }
      }
      if (res.data.status == 'success') {
        var all_browse = res.data.shop_info.self_all_browse;
        var all_release = res.data.all_release;

        that.setData({
          banner_info: res.data.banner_info,
          conven_type_info: res.data.conven_type_info,
          all_browse: all_browse,
          all_release: all_release,
          conven_info: res.data.conven_info,
          shop_info: res.data.shop_info,
          conven_top_info: res.data.conven_top_info,
          page: page,
          prodis: 'none',
        });
        // 隐藏导航栏加载框  
        wx.hideNavigationBarLoading();
        // 停止下拉动作  
        wx.stopPullDownRefresh();
        wx.hideLoading()
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})